<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('考勤打卡')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="clock-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>打卡日期：</label>
                                <input type="text" class="time-input" placeholder="请选择打卡日期" name="clockDate"/>
                            </li>
<!--                            <li>-->
<!--                                <label>打卡状态：</label>-->
<!--                                <input type="text" class="text" placeholder="请选择打卡状态" name="clockState"/>-->
<!--                            </li>-->
                            <li>
                                <label>补卡时间：</label>
                                <input type="text" class="time-input" placeholder="请选择补卡时间" name="replacementCardTime"/>
                            </li>
                            <input type="hidden" name="personneId"/>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">

                <button id="clockBtn" class="btn btn-primary " onclick="clock()" type="button"><i class="fa fa-check"></i>&nbsp;打卡</button>
                <a class="btn btn-warning" onclick="$.table.exportExcel()">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>


     <!--模态弹出层-->
     <div class="text-center">
         <button type="button" id="modalBtn" class="btn btn-primary" data-toggle="modal" data-target="#myModal" style="display: none">打开示例窗口</button>
     </div>
     <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
         <div class="modal-dialog">
             <div class="modal-content animated bounceInRight">
                 <div class="modal-header">
                     <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                     </button>
                     <h4 class="modal-title">我要补卡</h4>
                 </div>
                 <div class="modal-body">
                     <form class="form-horizontal m-t" id="commentForm" th:action="@{/}">
                         <div class="form-group">
                             <label class="col-sm-3 control-label">员工编号：</label>
                             <div class="col-sm-7">
                                 <input id="empId" name="id" minlength="2" type="text" class="form-control" readonly unselectable="on">
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-3 control-label">姓名：</label>
                             <div class="col-sm-7">
                                 <input id="userName" name="id" minlength="2" type="text" class="form-control" readonly unselectable="on">
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-3 control-label">部门：</label>
                             <div class="col-sm-7">
                                 <input id="dept" type="text" class="form-control" name="dept" readonly unselectable="on">
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-3 control-label">职位：</label>
                             <div class="col-sm-7">
                                 <input id="post" name="post" class="form-control" readonly unselectable="on">
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-3 control-label">补签卡类型：</label>
                             <div class="col-sm-7">
                                 <select>
                                     <option value="0">补卡</option>
                                 </select>
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-3 control-label">补签卡原因：</label>
                             <div class="col-sm-7">
                                 <select>
                                     <option value="0">忘记打卡</option>
                                     <option value="1">外出公差</option>
                                 </select>
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-3 control-label">备注：</label>
                             <div class="col-sm-7">
                                 <input type="text" name="remarks"/>
                             </div>
                         </div>
                     </form>
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                     <button type="button" class="btn btn-primary">保存</button>
                 </div>
             </div>
         </div>
     </div>
     <!--模态弹出层-->

    <th:block th:include="include :: footer" />
     <!--时间js-->
    <th:block th:include="include :: datetimepicker-js" />

    <script th:inline="javascript">
        //职位
        var postName = [[${@permission.getUserListPost().get(0).postName}]];
        //用户id
        var userid = [[${@permission.getPrincipalProperty('userId')}]];
        //租户id
        var tenantid = [[${@permission.getPrincipalProperty('tenantId')}]];
        //用户姓名
        var userName = [[${@permission.getPrincipalProperty('userName')}]];
        //部门
        var dept = [[${@permission.getPrincipalProperty('dept').deptName}]];
        //打卡状态数据
        var datas = [[${@dict.getType('sys_clock_status')}]];
        var editFlag = [[${@permission.hasPermi('system:clock:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:clock:remove')}]];
        var prefix = ctx + "system/clock";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "考勤打卡",
                columns: [
                {
                    field: 'clockDate',
                    title: '打卡日期'
                },
                {
                    field: 'clockWeek',
                    title: '打卡星期'
                },
                {
                    field: 'clockTime',
                    title: '打卡时间'
                },
                {
                    field: 'clockState',
                    title: '打卡状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'numberOdClocks',
                    title: '打卡次数'
                },
                {
                    field: 'replacementCardTime',
                    title: '补卡时间'
                },
                ]
            };
            $.table.init(options);
        });

        function replacement(clockId) {
            $("#modalBtn").click();
            //设置用户id
            $('#empId').val(userid);
            //用户姓名
            $('#userName').val(userName);
            //部门
            $('#dept').val(dept);
            //职位
            $('#post').val(postName);

            console.log("用户id！"+userid);
            console.log("用户名！"+userName);
            console.log("打卡id====>"+clockId);
            console.log("租户id====>"+tenantid)
        }

        // function leave(id) {
        //     console.log("请假按钮！"+id);
        // }
        //
        // function business(id) {
        //     console.log("出差按钮！"+id);
        // }


        function getWeekDate() {
            var now = new Date();
            var day = now.getDay();
            var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
            var week = weeks[day];
            return week;
        }

        //打卡事件
        function clock(){
            // var date = new Date();
            // //获取当前日期
            // var clockDate = date.toLocaleDateString();
            // //获取当前星期
            // var clockWeek = getWeekDate();
            // //获取打卡当前时间
            // var ttt = date.toLocaleString('Chinese', { hour12: false });
            // console.log(ttt);
            // var clockTime = ttt.substring(ttt.indexOf(' '));
            // //打卡次数
            // var numberOdClocks = 1;
            //员工编号
            var personnelId = userid;
            //租户id
            var tenantId = tenantid;
            console.log("租户id： "+tenantId)
            //后台Ajax请求
            $.ajax({
                type:"get",
                url: "/system/clock/daka",
                data: {personnelId, tenantId},
                success: function(result) {
                    if (result.msg == 'success' && result.code == 200) {
                        layer.msg("打卡成功,正在刷新数据……", {
                            icon: 1,
                            time: 2000,
                            shade: [0.1, '#8F8F8F']
                        },function() {
                            location.reload();
                        });
                    } else {
                        alert(result.msg);
                    }
                }
            });
        }
    </script>
</body>
</html>